package com.test.first;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;

import java.util.ArrayList;
import java.util.List;



public class FirstListActivity extends ListActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_first_list);
        //准备数据
        List<String> list1 = new ArrayList<String>();
        for(int i = 1;i<100;i++){
            list1.add("item" + i);
    }

        ListAdapter adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_expandable_list_item_1,list1);
        setListAdapter(adapter);

        Handler handler = new Handler(Looper.myLooper()){
            @Override
            public void handleMessage(@NonNull Message msg) {
                if (msg.what==9);{
                    ArrayList<String> list2 = (ArrayList<String>)msg.obj;
                    ListAdapter adapter = new ArrayAdapter<String>(FirstListActivity.this,
                            android.R.layout.simple_expandable_list_item_1,list2);
                    setListAdapter(adapter);
                }
            }
        };

        MyTask task = new MyTask();
        task.setHandler(handler);

        Thread t = new Thread(task);
        t.start();


    }
}